package com.jinyou.chengfengshop.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.jinyou.chengfengshop.MainActivity;
import com.jinyou.chengfengshop.R;

/**
 * 启动页
 * Created by zhuzhiqiang on 2018/9/20.
 */

public class StartActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_start);
        Handler myHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);

            }
        };
        myHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                goMain();
            }
        }, 2000);
    }


    //进入主界面
    private void goMain() {
        SharedPreferences sh = getSharedPreferences("user", Context.MODE_PRIVATE);
        String tocken = sh.getString("tocken","");
        Log.d("tocken",tocken);
        //edt.putString("tocken",obj.getString("token"));
        Intent intent;
        if(tocken.equals("")){
//            SharedPreferences.Editor edt = sh.edit();
//            edt.putString("tocken","4082640308995072S0r257Mf8di3uqOo");
//            edt.commit();
//            intent = new Intent(this, MainActivity.class);
//            startActivity(intent);

            intent= new Intent(this, LoginActivity.class);
            startActivity(intent);
        }else {

//            SharedPreferences.Editor edt = sh.edit();
//            edt.putString("tocken","4082640308995072S0r257Mf8di3uqOo");
            intent = new Intent(this, MainActivity.class);
            startActivity(intent);
        }

        finish();
    }

}
